﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//using Model;

/// <summary>
/// Description résumée de SiteManager
/// </summary>
/// 
namespace DAL
{
    public class SiteManager : ISiteManager
    {
        private IAATOEntities dbService;

        public SiteManager()
        {
            dbService = new IAATOEntities();
        }

        public bool addSite(SITE site)
        {
            try
            {
                dbService.SITEJeu.AddObject(site);
                dbService.SaveChanges();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public bool deleteSite(int siteId)
        {
            try
            {
                SITE site = (from s in dbService.SITEJeu
                             where s.ID == siteId
                             select s).First();

                dbService.DeleteObject(site);
                dbService.SaveChanges();
                return true;
            }

            catch (Exception ex)
            {
                return false;
            }

        }

        public bool updateSite()
        {
            try
            {
                dbService.SaveChanges();
                return true;
            }

            catch (Exception ex)
            {
                return false;
            }
        }

        public SITE getSiteById(int id)
        {
            try
            {
                return (from s in dbService.SITEJeu
                        where s.ID == id
                        select s).First();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public List<SITE> getAllSites()
        {
            try
            {
                return (from s in dbService.SITEJeu
                        orderby s.NOM
                        select s).ToList();
            }
            catch (Exception ex)
            {
                return null;
            }
        }


        public string getNom(int id)
        {
            try
            {
                return (from s in dbService.SITEJeu
                        where s.ID == id
                        select s.NOM).First();
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}